﻿using System;
using System.Data;
using System.Reflection;
using System.Web;
using System.Text;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using AnyOffice.Model;
using log4net;
namespace AnyOffice.general.ipanel
{
    public partial class user_info : BasePage
    {

        private static ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                string userId = (Request.QueryString["user_id"] == null) ? "" : Request.QueryString["user_id"].ToString();
                this.ViewState["UserId"] = userId;
                this.ViewState["UserName"] = "";
                if (userId == string.Empty)
                {
                    this.pnlMain.Visible = false;
                    this.litMessage.Text = base.ShowMessage("无此用户");
                }
                else
                {
                    DataTable table = new UsersDao().SelectByUserId(base.Conn, userId);
                    if (table.Rows.Count > 0)
                    {
                        this.ViewState["UserName"] = table.Rows[0]["UserName"].ToString();
                        this.litUserName.Text = table.Rows[0]["UserName"].ToString();
                        ConfigManager manager = new ConfigManager();
                        if (manager.RtxEnabled)
                        {
                            this.Page.RegisterClientScriptBlock("rtx", "<script type=\"text/javascript\" src=\"js/browinfo.js\"></script>\n<script type=\"text/javascript\" src=\"js/rtxint.js\"></script>");
                            this.litRTXStatus.Text = this.litRTXStatus.Text + "<img height=16 src=images/rtxoff.gif width=16 onload=RAP('" + userId + "') align=absmiddle showOffline>(RTX)&nbsp;";
                        }
                        if (new ConfigManager().SkypeButtonEnabled && (table.Rows[0]["Skype"] != DBNull.Value))
                        {
                            this.Page.RegisterClientScriptBlock("skype", "<script type=\"text/javascript\" src=\"js/skypeCheck.js\"></script>");
                            string str2 = table.Rows[0]["Skype"].ToString();
                            StringBuilder builder = new StringBuilder();
                            builder.Append("<style>\n");
                            builder.Append(".menuItem { font-family:ms sans serif,helvetica,arial,sans-serif; font-size:8pt; width:100%; padding-left:0; background-Color:menu; color:black; padding-top: 2px; padding-bottom: 2px; margin-bottom:0; margin-top:0; cursor: default; }\n");
                            builder.Append(".menuItemDefault { font-family:ms sans serif,helvetica,arial,sans-serif;  font-size:8pt;  font-weight:bold;  width:100%;  padding-left:0;  background-Color:menu;  color:black;  padding-top: 2px;  padding-bottom: 2px;  cursor: default; }\n");
                            builder.Append(".highlightItem {  font-family:ms sans serif,helvetica,arial, sans-serif;  font-size:8pt;  width:100%;  padding-left:0;  background-Color:highlight;  color:white;  padding-top: 2px;  padding-bottom: 2px;  cursor: default; }\n");
                            builder.Append("</style>\n");
                            builder.Append("<script>\n");
                            builder.Append("var cm=null;\n");
                            builder.Append("document.onclick = new Function(\"show(null)\"); \n");
                            builder.Append("function getPos(el,sProp) { \n");
                            builder.Append("\tvar iPos = 0; \n");
                            builder.Append("\twhile (el!=null) { \n");
                            builder.Append("\t\tiPos+=el[\"offset\" + sProp]; \n");
                            builder.Append("\t\tel = el.offsetParent; \n");
                            builder.Append("\t} \n");
                            builder.Append("\treturn iPos; \n");
                            builder.Append("} \n");
                            builder.Append("\n");
                            builder.Append("function show(el,m) {\n");
                            builder.Append("\tif (m) {\n");
                            builder.Append("\t\tm.style.display=''; \n");
                            builder.Append("\t\tm.style.pixelLeft = getPos(el,\"Left\"); \n");
                            builder.Append("\t\tm.style.pixelTop = getPos(el,\"Top\") + el.offsetHeight; \n");
                            builder.Append("\t} \n");
                            builder.Append("\tif ((m!=cm) && (cm)) cm.style.display='none'; \n");
                            builder.Append("\tcm=m; \n");
                            builder.Append("} \n");
                            builder.Append("\n");
                            builder.Append("function switchMenu() \n");
                            builder.Append("{ \n");
                            builder.Append("\tel=event.srcElement; \n");
                            builder.Append("\tif (el.className==\"menuItem\") \n");
                            builder.Append("\t{ \n");
                            builder.Append("\t\tel.className=\"highlightItem\"; \n");
                            builder.Append("\t} \n");
                            builder.Append("\telse if (el.className==\"highlightItem\") \n");
                            builder.Append("\t{ \n");
                            builder.Append("\t\tel.className=\"menuItem\"; \n");
                            builder.Append("\t} \n");
                            builder.Append("} \n");
                            builder.Append("</script> \n");
                            builder.Append("<a href=\"skype:" + str2 + "?call\"  onmouseover=\"show(this,ds1);\"  title=\"Skype\"><img src=\"http://mystatus.skype.com/smallicon/" + str2 + "\" border=\"0\" align=\"absmiddle\">(Skype)</a> \n");
                            builder.Append("<div id=\"ds1\" onmouseover=\"switchMenu()\"  onmouseout=\"switchMenu()\"  style=\"position:absolute;  display:none; width:130;  background-Color:menu;  border: 2px outset; \"> \n");
                            builder.Append("<div class=\"menuItem\"><a href=\"skype:" + str2 + "?call\" onclick=\"return skypeCheck();\"><span style=\"color:#000000;text-decoration: none;\">&nbsp;&nbsp;发起通话&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></a></div> \n");
                            builder.Append("<div class=\"menuItem\"><a href=\"skype:" + str2 + "?chat\" onclick=\"return skypeCheck();\"><span style=\"color:#000000;text-decoration: none;\">&nbsp;&nbsp;发送即时信息&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></a></div> \n");
                            builder.Append("<div class=\"menuItem\"><a href=\"skype:" + str2 + "?sendfile\" onclick=\"return skypeCheck();\"><span style=\"color:#000000;text-decoration: none;\">&nbsp;&nbsp;发送文件&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></a></div> \n");
                            builder.Append("<hr> \n");
                            builder.Append("<div class=\"menuItem\"><a href=\"skype:" + str2 + "?add\" onclick=\"return skypeCheck();\"><span style=\"color:#000000;text-decoration: none;\">&nbsp;&nbsp;加入Skype联系人&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></a></div> \n");
                            builder.Append("<div class=\"menuItem\"><a href=\"skype:" + str2 + "?userinfo\" onclick=\"return skypeCheck();\"><span style=\"color:#000000;text-decoration: none;\">&nbsp;&nbsp;查看资料&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></a></div> \n");
                            builder.Append("</div> \n");
                            this.litSkypeStatus.Text = builder.ToString();
                        }
                        this.litOAStatus.Text = "<img src=/images/on_status" + table.Rows[0]["State"].ToString() + ".gif align=absmiddle>(OA)&nbsp;";
                        this.litSex.Text = Convert.ToBoolean(table.Rows[0]["Sex"].ToString()) ? "男" : "女";
                        if (!Convert.ToBoolean(table.Rows[0]["IsHideBirthday"]))
                        {
                            this.litBirthday.Text = Convert.ToDateTime(table.Rows[0]["Birthday"].ToString()).ToString("yyyy-MM-dd");
                        }
                        else
                        {
                            this.litBirthday.Text = "<span title=\"不公开\" style=\"cursor:hand\">******</span>";
                        }
                        this.litOnlineTime.Text = Math.Floor((double)(Convert.ToDouble(table.Rows[0]["OnlineTime"].ToString()) / 60.0)).ToString() + "小时" + Convert.ToString((double)(Math.Floor(Convert.ToDouble(table.Rows[0]["OnlineTime"].ToString())) % 60.0)) + "分";
                        if (table.Rows[0]["Photo"] != DBNull.Value)
                        {
                            this.pnlPhoto.Visible = true;
                        }
                        this.litTelNoDept.Text = (table.Rows[0]["TelNoDept"] != DBNull.Value) ? table.Rows[0]["TelNoDept"].ToString() : "";
                        this.litFaxNoDept.Text = (table.Rows[0]["FaxNoDept"] != DBNull.Value) ? table.Rows[0]["FaxNoDept"].ToString() : "";
                        this.litAddressHome.Text = (table.Rows[0]["AddressHome"] != DBNull.Value) ? table.Rows[0]["AddressHome"].ToString() : "";
                        this.litZipHome.Text = (table.Rows[0]["ZipHome"] != DBNull.Value) ? table.Rows[0]["ZipHome"].ToString() : "";
                        this.litTelHome.Text = (table.Rows[0]["TelHome"] != DBNull.Value) ? table.Rows[0]["TelHome"].ToString() : "";
                        if (!Convert.ToBoolean(table.Rows[0]["IsHideMobile"]))
                        {
                            this.litMobile.Text = (table.Rows[0]["Mobile"] != DBNull.Value) ? table.Rows[0]["Mobile"].ToString() : "";
                        }
                        else if (table.Rows[0]["Mobile"] != DBNull.Value)
                        {
                            string str3 = table.Rows[0]["Mobile"].ToString();
                            for (int i = 0; i <= 9; i++)
                            {
                                str3 = str3.Replace(i.ToString(), "*");
                            }
                            this.litMobile.Text = "<span title=\"不公开\" style=\"cursor:hand\">" + str3 + "</span>";
                        }
                        this.litBp.Text = (table.Rows[0]["Bp"] != DBNull.Value) ? table.Rows[0]["Bp"].ToString() : "";
                        if (table.Rows[0]["Email"] != DBNull.Value)
                        {
                            this.litEmail.Text = "<a href=mailto:" + table.Rows[0]["Email"].ToString() + ">" + table.Rows[0]["Email"].ToString() + "</a>";
                        }
                        this.litOicq.Text = (table.Rows[0]["Oicq"] != DBNull.Value) ? table.Rows[0]["Oicq"].ToString() : "";
                        this.litIcq.Text = (table.Rows[0]["Icq"] != DBNull.Value) ? table.Rows[0]["Icq"].ToString() : "";
                        this.litMsn.Text = (table.Rows[0]["Msn"] != DBNull.Value) ? table.Rows[0]["Msn"].ToString() : "";
                        if (table.Rows[0]["Skype"] != DBNull.Value)
                        {
                            this.litSkype.Text = "<a href=\"skype:" + table.Rows[0]["Skype"].ToString() + "?add\" onclick=\"return skypeCheck();\" title=\"加入Skype联系人\">" + table.Rows[0]["Skype"].ToString() + "</a>";
                        }
                    }
                    else
                    {
                        this.pnlMain.Visible = false;
                        this.litMessage.Text = base.ShowMessage("无此用户或已删除！");
                    }
                    if (Request.QueryString["window"] != null)
                    {
                        this.litNav.Text = "<INPUT class=\"BigButton\" onclick=\"self.close();\" type=\"button\" value=\"关闭\">";
                    }
                    else
                    {
                        this.litNav.Text = "<INPUT class=\"BigButton\" onclick=\"history.back();\" type=\"button\" value=\"返回\">";
                    }
                }
            }
            catch (Exception exception)
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("", exception);
                }
            }
        } 

    }
}
